package tn.orange.canreminder.utils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateUtils {

	public static String[] strDays = new String[] { "lundi", "mardi",
			"mercredi", "jeudi", "vendredi", "samedi", "dimanche" };

	public static String[] strMonths = new String[] { "Janvier", "Février",
			"Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre",
			"Octobre", "Novembre", "Décembre" };

	public static Date stringToDate(String sDate) {
		Date d = null;

		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			d = sdf.parse(sDate);

		} catch (Exception e) {
			e.printStackTrace();
		}
		return d;
	}

	public static String getDate(String sdate) {

		Date date = stringToDate(sdate);
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);

		int week = calendar.get(Calendar.DAY_OF_WEEK);
		String day = strDays[week - 1];
		String month = strMonths[date.getMonth()];
		int year = date.getYear() + 1900;
		int day1 = calendar.get(Calendar.DATE);
		String minutes = "" + date.getMinutes();
		if (minutes.equals("0"))
			minutes = "00";

		return "Le " + day + " " + day1 + " " + month + " " + year + " à "
				+ date.getHours() + ":" + minutes;

	}
}
